package com.trusfort.redis;

import java.util.HashSet;
import java.util.Set;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

public class Test {
    private static final String REDIS_PASSWORD = "your_actual_password";
    
    private static void initRedisCluster() {
        try {
            Set<HostAndPort> clusterNodes = new HashSet();
            // 添加所有集群节点
            clusterNodes.add(new HostAndPort("172.10.3.110", 6379));
            clusterNodes.add(new HostAndPort("172.10.3.110", 6479));
            clusterNodes.add(new HostAndPort("172.10.3.110", 6579));
            clusterNodes.add(new HostAndPort("172.10.3.110", 6679));
            clusterNodes.add(new HostAndPort("172.10.3.110", 6779));
            clusterNodes.add(new HostAndPort("172.10.3.110", 6879));
            // ... 添加其他端口
            
        	GenericObjectPoolConfig config = new GenericObjectPoolConfig();
            
            
            JedisCluster cluster = new JedisCluster(clusterNodes, 2000, 2000, 100, "1234569", config);
            // 测试连接
            System.out.println(cluster.ping());;
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public static void main(String[] args) {
    	initRedisCluster();
	}
}